/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package org.amarena2d.examples.scenes.invader;

import com.android1.amarena2d.actions.base.Action;
import com.android1.amarena2d.actions.base.EventAction;
import com.android1.amarena2d.actions.base.Sequence;
import com.android1.amarena2d.actions.ease.EaseBackIn;
import com.android1.amarena2d.actions.ease.EaseBackOut;
import com.android1.amarena2d.actions.instant.Active;
import com.android1.amarena2d.actions.movement.MoveIn;
import com.android1.amarena2d.actions.movement.MoveOut;
import com.android1.amarena2d.commons.event.Event;
import com.android1.amarena2d.input.TouchListenerAdapter;
import com.android1.amarena2d.nodes.EntityGroup;
import com.android1.amarena2d.nodes.LayerNode;
import com.android1.amarena2d.nodes.SimpleLabel;
import com.android1.amarena2d.nodes.sprites.SharedSprite;
import com.android1.amarena2d.texture.BitmapFont;
import com.badlogic.gdx.graphics.Color;

public class Menu extends LayerNode {

    final EntityGroup box;
    final Action boxActionIn = EaseBackOut.$(MoveIn.$fromLeft(1).targetPosition(112, 130));
    final Action boxActionOut = Sequence.$(EaseBackIn.$(MoveOut.$toRight(1)), EventAction.$(Event.obtain(Events.START_GAME)), Active.$(false));

    public Menu() {

        box = new EntityGroup(112, 130);

        box.add(new SharedSprite("invader/box2.png"));

        final SimpleLabel label = new SimpleLabel(engine.getFontManager().getFont("impact.fnt", "impact.png"), 25, 50, Color.WHITE).setAlign(BitmapFont.HAlignment.CENTER);
        label.setText("Tap to Start");
        box.add(label);
        add(box);

        box.touch().makeTouchable(new TouchListenerAdapter() {
            @Override
            public boolean onTouchUp(float x, float y, int pointer, boolean isHit) {
                box.action().run(boxActionOut);

                return true;
            }
        });


    }


    public void show() {
        setActive(true);
        box.action().run(boxActionIn);
    }

    @Override
    protected void onEnter() {
        show();
    }

}
